import mongoose  from 'mongoose'
import BaseModel from "./base_model"

let Schema    = mongoose.Schema;
let ObjectId  = Schema.ObjectId;

/*
 * [type]
 * reply: xx 回复了你的话题
 * reply2: xx 在话题中回复了你
 * follow: xx 关注了你
 * at: xx ＠了你
 */

var MessageSchema = new Schema({
  appId:      { type: String, requried: true },
  type:       { type: String, requried: true },
  master_id:  { type: ObjectId },    // 给谁的？
  author_id:  { type: ObjectId },   // 谁发的？
  topic_id:   { type: ObjectId },
  reply_id:   { type: ObjectId },
  has_read:   { type: Boolean, default: false },
  create_at:  { type: Date, default: Date.now }
});
MessageSchema.plugin(BaseModel);
MessageSchema.index({master_id: 1, has_read: -1, create_at: -1});

mongoose.model('Message', MessageSchema);
